package com.wnnight.wys.serviceImpl.car;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnnight.wys.entity.car.Car;
import com.wnnight.wys.mapper.car.CarMapper;
import com.wnnight.wys.service.car.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName: CarServiceImpl
 * @Description: Service层Car实现
 * @author: CHX42
 * @date: 2022/8/28-13:34
 * @version: v1.0
 */
@Service
@Transactional
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {
    @Autowired
    private CarMapper carMapper;

    @Override
    public void insert(Car car) {
        carMapper.insert(car);
    }

    @Override
    public List<Car> getAll(Car car) {
//       return carMapper.getAll(car);
        return null;
    }

    /**
     * @Author CHX42
     * @Description 车辆车位到期续费
     * @Date  2022/8/29  16:42
     * @Param [car 续费车辆信息，需要封装车辆的id【car.id】与续费的季度【car.xfTime】]
     * @return void
     **/
    @Override
    public void xfCar(Car car, Wrapper wrapper) {
        car.setEndTime(String.valueOf(DateUtil.offsetMonth(DateUtil.parse(car.getEndTime()), car.getXfTime() * 3)));
        carMapper.update(car,wrapper);
    }

    @Override
    public Page<Car> getPage(IPage<Car> carPage, Wrapper wrapper) {
        return carMapper.getPage(carPage,wrapper);
    }

    @Override
    public Integer getIdByPhone(String phone) {
        return carMapper.getLandlordByPhone(phone);
    }

    @Override
    public List<Car> getByLandlordId(Integer landlordId) {
        QueryWrapper<Car> carWrapper = new QueryWrapper<>();
        carWrapper.eq("wys_car.landlord_id",landlordId);
        return carMapper.getPage(new Page<>(1,100),carWrapper).getRecords();
    }
}
